#pragma once
#include "List.h"
using namespace std;
#include <string>
#include <sstream>
#include <fstream>

template <class INFO>
struct Node
{
	Node<INFO>(){ this->next=nullptr; }
	Node<INFO>(INFO info){ this->info=info; this->next=nullptr; }
	INFO info;
	Node<INFO> * next;

	~Node<INFO>()
	{
	}
};

template <class INFO>

class List
{

private:
	Node <INFO> *head;
	Node <INFO> *tail;

public:
	List(void)
	{
		head = tail = nullptr;
	}
	void add_at_head(INFO info)
	{
		if ( head == nullptr)
		{
			head = new Node<INFO>(info);
			tail = head;
		}
		else
		{
			Node<INFO> *n = new Node<INFO>(info);
			n->next = head;
			head = n;
		}
	}
	string str()
	{
		ostringstream oss;
		Node<INFO> *n= head;
		if ( n == nullptr)
			return "";
		else
		{
			do
			{
				oss << n->info <<"\n";
				n = n-> next;
			}
			while ( n!= nullptr);
		}

		return oss.str();
	}
	Node <INFO> * search(INFO & info)
	{
		Node<INFO>	* n = head;
		if ( n == nullptr)
			return nullptr;
		else
		{
			do
			{
				if ( n-> info == info)
					return n;
				n = n -> next;
			}
			while (n != nullptr);
		}
		return nullptr;
	}


	~List()
	{
		Node<INFO> * n = head;
		Node<INFO> * d;
		while (n!= nullptr)
		{
			d = n;
			n = n-> next;
			delete d;
		}
	}

};




